package com.yunfeng.common.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunfeng.common.log.Log;
import com.yunfeng.common.service.CacheService;
import com.yunfeng.common.util.AjaxObject;

@Controller
@RequestMapping("/management/security/cacheManage")
public class CacheManageController {
	@Autowired
	private CacheService cacheService;

	private static final String INDEX = "management/security/cacheManage/index";

	@RequiresPermissions("CacheManage:view")
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index() {
		return INDEX;
	}

	@Log(message = "进行了缓存清理。")
	@RequiresPermissions("CacheManage:edit")
	@RequestMapping(value = "/clear", method = RequestMethod.POST)
	public @ResponseBody
	String clear() {
		cacheService.clearAllCache();

		return AjaxObject.newOk("清除缓存成功！").setCallbackType("").toString();
	}
}
